package com.prd.dto;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 菜单（权限）数据表
 * </p>
 *
 * @author lizhaoyi
 * @since 2024-01-09
 */
@Data
public class SysMenuDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键id")
    private Long id;

    @ApiModelProperty(value = "名称")
    @NotBlank(message = "菜单名称不能为空")
    @Size(min = 0, max = 50, message = "菜单名称长度不能超过50个字符")
    private String name;

    @ApiModelProperty(value = "权限标识")
    private String permission;

    @ApiModelProperty(value = "菜单类型，1-职能类型；2-公共权限")
    private Integer menuType;

    @ApiModelProperty(value = "排序")
    private Integer sort;

    @ApiModelProperty(value = "父菜单id")
    private Long parentId;

    @ApiModelProperty(value = "路由地址")
    private String path;

    @ApiModelProperty(value = "菜单图标")
    private String icon;

    @ApiModelProperty(value = "组件路径")
    private String component;

    @ApiModelProperty(value = "状态")
    private Integer status;

    @ApiModelProperty(value = "是否可见")
    private Integer visible;

    private String creator;

    private LocalDateTime createTime;

    private String updater;

    private LocalDateTime updateTime;

    private Integer deleted;

    @ApiModelProperty(value = "子菜单")
    private List<SysMenuDTO> children;

    public boolean isAdmin() {

        return isAdmin(this.id);
    }

    public static boolean isAdmin(Long userId){
        return userId != null && 1L == userId;
    }

    public boolean isChildMenu(Long menuId){

        return this.getParentId().equals(menuId);
    }

}
